package com.jason.service;

import com.jason.config.CacheKeyManager;
import com.jason.mapper.VideoMapper;
import com.jason.model.entity.Video;
import com.jason.model.entity.VideoBanner;
import com.jason.utlis.BaseCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class VideoServiceImpl implements VideoService {
    @Autowired
    private VideoMapper videoMapper;
    @Autowired
    private BaseCache baseCache;
    @Override
    public List<Video> videoList() {
        return videoMapper.videoList();
    }

    @Override
    public List<VideoBanner> listBanner() {
        try {
           Object cacheObj= baseCache.getTenMinuteCache().get(CacheKeyManager.INDEX_BANNER_KEY,()->{
                List<VideoBanner> bannerList=  videoMapper.listVideoBanner();
                return bannerList;
            });
           if (cacheObj instanceof List){
               List<VideoBanner> bannerList=(List<VideoBanner>)cacheObj;
               return bannerList;
           }
        }catch (Exception e){

        }

        return null;
    }

    @Override
    public Video findDetailById(int videoId) {
        //代办  需要使用Mybatis关联查询

//        Video video=videoMapper.findDetailById(videoId);
        return videoMapper.findDetailById(videoId);
    }
}
